package top.stmo.redis.jedis;


import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import redis.clients.jedis.Jedis;

import java.util.Map;

public class JedisTest1 {

    private Jedis jedis;

    //初始化方法
    @BeforeEach
    void setUp() {
        jedis = new Jedis("localhost", 6379);
//        localhost.auth("123321");
        jedis.select(0);
    }

    @Test
    public void testString() {
        //存入数据
        String set = jedis.set("name", "杰克");
        System.out.println(set);
        String name = jedis.get("name");
        System.out.println(name);
    }

    @Test
    public void testHash() {
        //存入数据
        jedis.hset("us:er","name","张三");
        jedis.hset("us:er","age","22");

        //取出数据
        Map<String, String> user = jedis.hgetAll("us:er");
        System.out.println(user);
    }


    @AfterEach
    void tearDown() {
        if (jedis != null) {
            jedis.close();          //销毁jedis
        }
    }
}
